﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Runtime.InteropServices;
using System.Web;
using System.Web.Configuration;

namespace CkSoftware.GroupMeChatModule.Managers
{
	public static class SessionIdProvider
	{
		public static string GetSessionId()
		{
			if (HttpContext.Current == null)
			{
				return string.Empty;
			}

			var sessionIdCookie = HttpContext.Current.Request.Cookies[GetSessionIdCookieName()];

			if (sessionIdCookie != null && !string.IsNullOrEmpty(sessionIdCookie.Value))
			{
				return sessionIdCookie.Value;
			}

			return string.Empty;
		}

		private static string GetSessionIdCookieName()
		{
			var sessionStateSettings = (SessionStateSection) ConfigurationManager.GetSection("system.web/sessionState");
			return sessionStateSettings.CookieName;
		}
	}
}